package de.planethold.sevenloadj;

import java.util.Calendar;

import org.w3c.dom.Element;

public class Token {
	private String type;
	private boolean valid;
	private Calendar validUntil;
	private String id;
	
	public Token(Element element) {
		 Element tokenElement = (Element)element.getElementsByTagName("token").item(0);
		 type = tokenElement.getAttribute("type");
		 valid = Utiliy.getBoolean(tokenElement.getAttribute("valid"));
		 validUntil = Utiliy.getCalendar(tokenElement.getAttribute("valid-until"));
		 id = tokenElement.getChildNodes().item(0).getNodeValue();
	}

	public Token() {
		valid = false;
	}

	public String toString() {
		return "type: " + type + "\n"
		+ "valid: " + valid + "\n"
		+ "created: " + Utiliy.printCalendar(validUntil) + "\n"
		+ "id: " + id + "\n"
		;
	}
	
	public String getId() {
		return id;
	}

	public String getType() {
		return type;
	}

	public boolean isValid() {
		return valid;
	}

	public Calendar getValidUntil() {
		return validUntil;
	}
}
